<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="user-scalable=no, width=device-width"/>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="css/jquery.mobile-1.4.4/jquery.mobile-1.4.4.min.css">
        <link rel="stylesheet" href="css/jquery.mobile-1.4.4/jquery.mobile.structure-1.4.4.min.css">
        <link rel="stylesheet" href="css/jquery.mobile-1.4.4/jquery.mobile.inline-png-1.4.4.min.css">
        <link rel="stylesheet" href="css/jquery.mobile-1.4.4/jquery.mobile.inline-svg-1.4.4.min.css">
        <link rel="stylesheet" href="css/jquery.mobile-1.4.4/jquery.mobile.external-png-1.4.4.min.css">
        <!-- Choix du thème -->
        <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css">
        <link rel="stylesheet" href="css/bootstrap/jquery.mobile.icons.min.css">
        <!-- JavaScript -->
        <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="js/jquery.mobile-1.4.4.min.js"></script>
        <script type="text/javascript" src="js/datebox/jqm-datebox.core.js"></script>
        <script type="text/javascript" src="js/datebox/jqm-datebox.mode.datebox.js"></script>
        <title></title>
    </head>
    <body>

        <div data-role="page" id="Projet"  data-dom-cahe=true>

            <?php
            session_start();
            $idUser = $_SESSION["id"];
            // echo "$idUser";


            $prevlink = 'accueil.php';
            $headerText = 'Liste des examens';
            include 'includes/header.php';
            ?>
            <div data-role="content">
                <?php
                // Montrer les erreurs
                ini_set('display_errors', 1);
                ini_set('display_startup_errors', 1);
                error_reporting(-1);
                require_once '../controller/AbonExamenManager.php';
                require_once '../controller/ExamenManager.php';
                include_once '../model/config.php';
                require_once '../model/Examen.php';

                if (isset($_POST['valider']) && !empty($_POST['choix'])) {
                    $var = $_POST['choix'];
                    $manager = new ExamenManager($bdd);
                    foreach ($var as $valeur) {

                        $list2 = $manager->getList($valeur);

                        foreach ($list2 as $examen) {
                            $libelle = $examen->getLibelle();
                            $id = $valeur;
                            $user = $idUser;
                        }
                        $abonExamen = new AbonExamen($user, $id, $libelle);

                        $manager2 = new AbonExamenManager($bdd);
                        $manager2->add($abonExamen);
                    }
                }



                $manager2 = new AbonExamenManager($bdd);
                $list2 = $manager2->getListAbonExamen($idUser);
                foreach ($list2 as $abonExamen) {
                    $libelle = utf8_encode($abonExamen->getLibelle());
                    $id = $abonExamen->getIdExamen();
                    $date = $manager2->getDate($id);

                    $now1 = date("Y-m-d");
                    $now2 = new DateTime($now1);
                    $now3 = $now2->format("Ymd");

                    $date2 = new DateTime($date);
                    $date3 = $date2->format("Ymd");

                    if ($date3 > $now3) {
                        echo '<a data-transition=flip href="Tache.php?idExamen=' . $id . '" data-role="button">';
                        echo $libelle;
                        echo"<span class='ui-li-count'>$date </span>";
                        echo '</a>';
                    }
                }
                ?>

                <a href="choixClasseExamen.php" data-role="button" data-icon="plus" data-transition="flip" data-theme="b"> Ajouter des examens </a>    
            </div>

            <div data-role="footer" data-theme="e" data-position="fixed" >
                <h1> &copy INSA TOULOUSE</h1>
            </div>
        </div>


    </body>

</html>